using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

namespace NiSis
{
    public partial class Package : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                LaunchPackage();
                lblPackage.Text = ConfigurationManager.AppSettings["PackageMessagge"] ?? string.Empty;   
            }
            catch (Exception ex)
            {
                lblPackage.Text = string.Format("{0}:{1} {2}", ConfigurationManager.AppSettings["PackageErrorMessagge"] ?? string.Empty, ex.Message, ex.StackTrace);
               
            }
            

        }
        /// <summary>
        /// Lancia la query contenuta all'interno del file package
        /// </summary>
        protected void LaunchPackage()
        {
            string query = File.ReadAllText(ConfigurationManager.AppSettings["PackageSql"].ToString());
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["PackageConnectionString"].ToString()))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(query, conn))
                    cmd.ExecuteNonQuery();
            }
        }
    }
}
